/*
  This file is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN FILE: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @filesource     $URL$
 */

#ifndef FILEABSTRACT_H_
#define FILEABSTRACT_H_

#include "../EnumAbstract.h"

template<template<typename> class File, typename Int>
class FileAbstract : public EnumAbstract<File<Int>, Int> {
public:
	static const Int COUNT = 9;
	static const File<Int> A();
	static const File<Int> B();
	static const File<Int> C();
	static const File<Int> D();
	static const File<Int> E();
	static const File<Int> F();
	static const File<Int> G();
	static const File<Int> H();
public:
	static const File<Int> BEGIN() { return File<Int>::A(); }
	static const File<Int> RBEGIN() { return File<Int>::H(); }
public:
	std::string toStr() const {
		std::string ret;
		if      ( this->me_c() == File<Int>::A() ) ret = "a";
		else if ( this->me_c() == File<Int>::B() ) ret = "b";
		else if ( this->me_c() == File<Int>::C() ) ret = "c";
		else if ( this->me_c() == File<Int>::D() ) ret = "d";
		else if ( this->me_c() == File<Int>::E() ) ret = "e";
		else if ( this->me_c() == File<Int>::F() ) ret = "f";
		else if ( this->me_c() == File<Int>::G() ) ret = "g";
		else if ( this->me_c() == File<Int>::H() ) ret = "h";
		else                                       ret = "-";

		return ret;
	}

	void fromStr(const std::string str) {
		if      ( "a" == str ) this->me() = File<Int>::A();
		else if ( "b" == str ) this->me() = File<Int>::B();
		else if ( "c" == str ) this->me() = File<Int>::C();
		else if ( "d" == str ) this->me() = File<Int>::D();
		else if ( "e" == str ) this->me() = File<Int>::E();
		else if ( "f" == str ) this->me() = File<Int>::F();
		else if ( "g" == str ) this->me() = File<Int>::G();
		else if ( "h" == str ) this->me() = File<Int>::H();
		else                   this->me() = File<Int>::NIL();
	}
};

#endif /* FILEABSTRACT_H_ */
